#ifndef __DB1_H__
#define __DB1_H__
#include <mysql/mysql.h>
#include <cjson/cJSON.h>
#include <string.h>

#define HOST "localhost"
#define USER "root"
#define PORT 980913
#define PWD  "root"
#define DBNAME "stm32db"

// -------基础数据库函数-------
int connect_db(MYSQL *mysql);  // 连接数据库的函数
void close_db(MYSQL *mysql); // 关闭数据库

int query_db(MYSQL *mysql, const char *sql, const long sqllen, void (*callback)(cJSON *rowobj));
int dml_db(MYSQL *mysql, const char *sql, const long sqllen);  //DML语句执行的函数

cJSON * query_jsonarray(MYSQL *mysql, const char *sql, const long sqllen);

// -------业务处理数据库函数--------
cJSON *fetch_row(MYSQL *mysql,char *sql, long sqllen); // 用户登录

int query_rows(MYSQL *mysql, char *sql); // 查询sql执行后的行数
int count_rows(MYSQL *mysql, char *sql); // 统计sql执行语句的行数


extern unsigned char char_to_hex(unsigned char x);
extern int is_alpha_number_char(unsigned char c);

// url编码实现
extern void urlencode(unsigned char *src, int src_len, unsigned char *dest, int dest_len);
// 解url编码实现
extern unsigned char *urldecode(unsigned char *encd, unsigned char *decd);


#endif